package it.unibo.refolding.pico;


import java.util.List;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

public class PreviousAndCurrentLists {
	
	public final List<ParsedAndTargetFile> previous;
	public final List<ParsedAndTargetFile> current;
	public final List<ParsedAndTargetFile> unparseable;

	public PreviousAndCurrentLists(
		List<ParsedAndTargetFile> previous,
		List<ParsedAndTargetFile> current,
		List<ParsedAndTargetFile> unparseable) {
		this.previous = checkParsed(previous);
		this.current = checkParsed(current);
		this.unparseable = Preconditions.checkNotNull(unparseable);
	}

	private List<ParsedAndTargetFile> checkParsed(List<ParsedAndTargetFile> a) {
		for (ParsedAndTargetFile x : a) {
			Preconditions.checkArgument(!x.isEmpty());
		}
		return a;
	}

	public int size() {
		return previous.size() + current.size() + unparseable.size();
	}

  public static PreviousAndCurrentLists of(ParsedAndTargetFile x) {
    // Note that x could be null.
    return new PreviousAndCurrentLists(
      ImmutableList.<ParsedAndTargetFile>of(), !x.isEmpty() ? ImmutableList.of(x)
        : ImmutableList.<ParsedAndTargetFile>of(),
      !x.isEmpty() ? ImmutableList.<ParsedAndTargetFile>of() : ImmutableList.of(x));
  }
//	
//  public static PreviousAndCurrentLists of(ParsedAndTargetFile x) {
//    List<ParsedAndTargetFile> current = new ArrayList<>(x.parsed.iterations());
//    List<ParsedAndTargetFile> unparseable = new ArrayList<>(x.parsed.iterations());
//    for (PlainPicoData y : x.parsed.picoDataList) {
//      (y != null ? current : unparseable).add(new ParsedAndTargetFile(y, x.targetFile));
//    }
//    // Note that x could be null.
//    return new PreviousAndCurrentLists(
//      ImmutableList.<ParsedAndTargetFile> of(),
//      Collections.unmodifiableList(current),
//      Collections.unmodifiableList(unparseable));
//  }

  public static PreviousAndCurrentLists of(
    List<PlainPicoDataAndTargetFile> previous, List<PlainPicoDataAndTargetFile> current,
    List<PlainPicoDataAndTargetFile> unparseable) {
    return new PreviousAndCurrentLists(
      ParsedAndTargetFile.from(previous),
      ParsedAndTargetFile.from(current),
      ParsedAndTargetFile.from(unparseable)
      );
  }

  public static PreviousAndCurrentLists of(PlainPicoDataAndTargetFile a) {
    return of(ParsedAndTargetFile.of(a));
  }
}
